package com.prd.controller;

import com.prd.constant.CheckStatus;
import com.prd.dto.SalesSignDto;
import com.prd.model.*;
import com.prd.service.EntContactForeignService;
import com.prd.util.AjaxResult;
import com.prd.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "联络函(对外)/商函")
@RestController
@RequestMapping("/api/entContactForeign")
public class EntContactForeignController extends BaseController {

    @Autowired
    private EntContactForeignService entContactForeignService;

    @ApiOperation("查询列表")
    @GetMapping("list")
    public TableDataInfo list(@ApiParam("日期") String day, @ApiParam("0：全部、1：我发起、2：我接收、3：我制单、4：待确认、5：已确认、6：待审批、7：审批通过、8：审批不通过") Integer catalog) {
        startPage();
        List<EntContactForeign> list = entContactForeignService.listInfo(day, catalog);
        return getDataPage(list);
    }

    @ApiOperation("添加信息")
    @PostMapping("add")
    public AjaxResult add(@RequestBody EntContactForeign entContactForeign) {
        return toAjax(entContactForeignService.insertInfo(entContactForeign));
    }

    @ApiOperation("修改信息")
    @PostMapping("update")
    public AjaxResult update(@RequestBody EntContactForeign entContactForeign) {
        return toAjax(entContactForeignService.updateInfo(entContactForeign));
    }

    @ApiOperation("查询详情")
    @GetMapping("details/{id}")
    public AjaxResult details(@PathVariable("id") Long id) {
        return AjaxResult.success(entContactForeignService.details(id));
    }

    @ApiOperation("审核通过")
    @PostMapping("pass")
    public AjaxResult pass(@RequestBody EntContactForeignCheck entContactForeignCheck) {
        entContactForeignCheck.setType(CheckStatus.TWO.getCode());
        return toAjax(entContactForeignService.pass(entContactForeignCheck));
    }

    @ApiOperation("审核不通过")
    @PostMapping("notPass")
    public AjaxResult notPass(@RequestBody EntContactForeignCheck entContactForeignCheck) {
        entContactForeignCheck.setType(CheckStatus.THREE.getCode());
        return toAjax(entContactForeignService.pass(entContactForeignCheck));
    }

    @ApiOperation("增加抄送人")
    @PostMapping(value = "addMake/{budgetId}/{makes}")
    public AjaxResult addMake(@ApiParam("联络函ID") @PathVariable("foreignId") Long foreignId, @ApiParam("抄送人（多个,分开）") @PathVariable("makes") Long[] makes) {
        return toAjax(entContactForeignService.addMake(foreignId, makes));
    }

    @ApiOperation("发出方签署")
    @PostMapping("salesSign")
    public AjaxResult salesSign(@RequestBody SalesSignDto salesSignDto) {
        return toAjax(entContactForeignService.salesSign(salesSignDto));
    }

    @ApiOperation("接收方签署")
    @PostMapping("acceptorSign")
    public AjaxResult acceptorSign(@RequestBody EntContactForeignSign entContactForeignSign) {
        return toAjax(entContactForeignService.acceptorSign(entContactForeignSign));
    }

}
